﻿<%@ Page Language="C#" MasterPageFile="~/Shared/Masters/Form.master" AutoEventWireup="true" CodeFile="PerfNoticeAdd.aspx.cs" 
Inherits="Modules_Personal_PerfNoticeAdd" Title="绩效得分公示设置" %>

<asp:Content ID="Content2" ContentPlaceHolderID="idFormMain" Runat="Server">
<script src="../../Scripts/DatePicker/WdatePicker.js" language="javascript"></script>
<script type="text/javascript" language="javascript" src="../../Scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" language="javascript" src="../../Scripts/jquery.checktree.0.3.min.js"></script>
<script type="text/javascript" language="javascript">
    var m_dpmtRootNode = null;
    $(function(){
        var sl = document.createElement("link");
        sl.type = "text/css";
        sl.rel = "stylesheet";
        sl.href = "../../Scripts/css/checktree/checktree.css";
        document.getElementsByTagName("head")[0].appendChild(sl);
    
        m_dpmtRootNode = $('#treeRoot');
	    showDpmtTree('#treeRoot', '#treeRoot', false, false);
    });
    
    function showDpmtTree(parentObj, rootTag, showCheck, withUpDown) {
        var tmp = $(parentObj);
        var needToLoad = false;
    	
        if (parentObj == rootTag) {
	        if (tmp.find("li").length <= 1) {
		        needToLoad = true;
	        }
        }
        else {
	        if (!tmp.parent().attr("loaded")) {
		        needToLoad = true;
	        }
        }
    	
        if (needToLoad) {
	        getData(parentObj, function(json){
		        parseAllTree(json[0], parentObj, rootTag, showCheck, withUpDown);
	        });
        }
    }
    
    function getData(parentDpmt, callback) {
        var axel = Math.random() + "";
        var num = axel * 1000000000000000000;
        var pObj = $(parentDpmt);
        var pid = "";
        if (pObj) {
	        var lbl = pObj.parent().find("label");
	        if (lbl) {pid = lbl.attr("cid");}
        }
    	
        $.getJSON(
	        "../System/OrgTreeAjax.aspx?ft=all",
	        {dc:num, ppid:pid, getTree:1},
	        function(json) {
		        callback(json);
	        }
        );
    }
    
    function parseAllTree(data, target, rootTag, sc, wud) {
        if (data && data.dpmt) {
	        var root = data.dpmt[0];
	        var startIndex = 0;
	        var rootElement = "";
    		
	        if (target != rootTag) {
		        if (data.dpmt.length > 0) {
			        var cid = $(target).parent().find("label").attr("cid");
			        root = {id:cid};
			        startIndex = 0;
		        }
		        else {
			        root = null;
		        }
	        }
	        else {
	            root = {id:0};
	        }
    		
	        rootElement += buildDepartmentTag(root, data.dpmt.slice(startIndex, data.dpmt.length), true);
    		
	        $(target).html(rootElement);
	        buildDpmtTree(target, rootTag, sc, wud);
        }
    }
    
    function buildDpmtTree(target, rootNode, sc, wud) {
        var tt = $(target);
        var rn = m_dpmtRootNode;

        tt.checkTree({
	        rootObj:rn,
	        index: target == 'treeRoot' ? 1 : 3,
	        showCheck: sc,
	        withUpDown: false,
	        onExpand:function(obj){
		        if (!obj.attr("loaded")) {
			        var tmp = obj.find("ul");
			        tmp.html("loading...");
			        if (tmp && tmp.length > 0){
				        showDpmtTree(tmp[0], rn, sc, wud);
			        }
		        }
		        obj.attr("loaded","true");
	        }
        });
    	
        if (target == rootNode) {
	        var r = tt.find('.arrow');
	        if (r.length > 0) {
		        var tmp = $(r[0]);
		        tmp.parent().attr("loaded","true");
		        tmp.trigger('click');
	        }
        }
    }
    
    function buildDepartmentTag(p, t, isAddChild) {
        var h = "";
        for(var i = 0; i < t.length; i++) {
	        var tmp = t[i];
	        if (tmp.parentId == p.id || tmp.parentId == 0) {
		        h += "<li class='parent'><input type='checkbox' class='cb' /><img src='../../Scripts/css/checktree/images/02.jpg' style='width:22px;height:16px;padding:0'/><label type='dpmt' cid='" + tmp.id + "' pid='" + tmp.parentId + "' orgType='" + tmp.type + "' status='" + tmp.status + "' code='" + tmp.code + "'>" + tmp.name + "</label>";
    			
		        var child = buildDepartmentTag(tmp, t.slice(i + 1, t.length), true);
		        var mbt = "";
		        if (child != "" || mbt != null) {
			        h = h + "<ul>" + child + mbt + "</ul>";
		        }
		        h += "</li>";
	        }
        }
    	
        return h;
    }
    
    function getSelectedDpmtNode() {
        var lbs = $('#treeRoot').find('label');
        if (lbs.length > 0) {
	        for(var i = 0; i < lbs.length; i++) {
		        var lbl = lbs[i];
		        if (lbl.getAttribute("selected") == "true") {
			        return lbl;
		        }
	        }
        }
        return null;
    }
</script>
    <h2>
       <asp:Label ID="lblTitle" runat="server" Text="绩效得分公示设置" ></asp:Label>
    </h2>
<div>
    <table cellpadding='2' cellspacing='1' class='ow_fim_mg' width='100%'>
                <tr>
                    <td class='fi_l'>
                        <asp:Label ID="Label3" runat="server" Text="公示天数:"></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:TextBox ID="txtNoticeLen" runat="server" Width="120px" Text="5"></asp:TextBox>
                        <asp:CompareValidator ID="cvScore" runat="server" ControlToValidate="txtNoticeLen" ErrorMessage="公示天数大于等于0"
                           Operator="GreaterThanEqual" Type="Integer" ValueToCompare="0" ValidationGroup="oss"></asp:CompareValidator>
                           <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="请输入公示天数" ValidationGroup="oss"
                    ControlToValidate="txtNoticeLen">*</asp:RequiredFieldValidator>
                    </td>
                    <td class='fi_l'>
                        <asp:Label ID="Label1" runat="server" Text="申诉天数:"></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:TextBox ID="txtAppealLen" runat="server" Width="120px" Text="5"></asp:TextBox>
                        <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtAppealLen" ErrorMessage="申诉天数大于等于0"
                           Operator="GreaterThanEqual" Type="Integer" ValueToCompare="0" ValidationGroup="oss"></asp:CompareValidator>
                           <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="请输入申诉天数" ValidationGroup="oss"
                    ControlToValidate="txtAppealLen">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td class='fi_l'>
                        <asp:Label ID="Label2" runat="server" Text="公示对象:"></asp:Label><font color='red'>*</font>
                        <input type="hidden" runat="server" ID="hdnOrgID" class="js_unique_orgid" value="" />
                    </td>
                    <td class='fi_r' colspan="3">
                        <ul id="treeRoot" class="tree1 tree" style="margin-left: 5px;OVERFLOW:auto; height:220px;">
			                <li>
				                <label>loading...</label>
			                </li>
		                </ul>
                    </td>
                </tr>
            </table>
</div>

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
        ShowSummary="False" ValidationGroup="oss" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="idFormButton" Runat="Server">
  <asp:Button ID="btnSave" runat="server" Text="保存"  ValidationGroup="oss"
        OnClick="btnSave_Click" OnClientClick="doSave();" />
    <asp:Button ID="CloseButton" runat="server" Text="关闭" 
        OnClientClick="return closeForm();" />   
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="idScript" runat="Server">

    <script type="text/javascript">
        function closeForm() {
            window.returnValue="false";
            window.opener=null;
            window.close();
            return false;
        } 
       
       function doSave() {
            var obj = getSelectedDpmtNode();
            if(obj) {
                $("input.js_unique_orgid").val(obj.getAttribute("cid"));
            }
        }
    </script>

</asp:Content>



